// AppToolBar class : application toolbar

package appForm;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Insets;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import appPref.Para;

public class AppToolBar extends JToolBar implements ActionListener {

  private Para para = Para.getPara();

  private String selectTip       = para.getT("selectTip");
  private String increaseTip     = para.getT("increaseTip");
  private String decreaseTip     = para.getT("decreaseTip");
  private String picture1Tip     = para.getT("picture1Tip");
  private String picture2Tip     = para.getT("picture2Tip");
  private String picture3Tip     = para.getT("picture3Tip");
  private String picture4Tip     = para.getT("picture4Tip");
  private String picture5Tip     = para.getT("picture5Tip");
  private String picture6Tip     = para.getT("picture6Tip");
  private String picture7Tip     = para.getT("picture7Tip");
  private String picture8Tip     = para.getT("picture8Tip");
  private String picture9Tip     = para.getT("picture9Tip");
  private String picture10Tip    = para.getT("picture10Tip");
  private String picture11Tip    = para.getT("picture11Tip");
  private String picture12Tip    = para.getT("picture12Tip");
  private String picture13Tip    = para.getT("picture13Tip");
  private String picture14Tip    = para.getT("picture14Tip");
  private String picture15Tip    = para.getT("picture15Tip");

  public static final	int	SELECT      =	1;
  public static final	int	INCREASE    =	2;
  public static final	int	DECREASE    =	3;
  public static final	int	PICTURE1B	  =	4;
  public static final	int	PICTURE2B	  =	5;
  public static final int PICTURE3B   = 6;
  public static final int PICTURE4B   = 7;
  public static final int PICTURE5B   = 8;
  public static final int PICTURE6B   = 9;
  public static final int PICTURE7B   = 10;
  public static final int PICTURE8B   = 11;
  public static final int PICTURE9B   = 12;
  public static final int PICTURE10B  = 13;
  public static final int PICTURE11B  = 14;
  public static final int PICTURE12B  = 15;
  public static final int PICTURE13B  = 16;
  public static final int PICTURE14B  = 17;
  public static final int PICTURE15B  = 18;

	private static final String SELECT_BUTTON     = "image/button/selectButton.gif";
	private static final String INCREASE_BUTTON   = "image/button/increaseButton.gif";
	private static final String DECREASE_BUTTON   = "image/button/decreaseButton.gif";
  private static final String PICTURE1_BUTTON   = "image/button/biblio2Button.gif";
  private static final String PICTURE2_BUTTON   = "image/button/bureauButton.gif";
  private static final String PICTURE3_BUTTON   = "image/button/chaise4Button.gif";
  private static final String PICTURE4_BUTTON   = "image/button/table1Button.gif";
  private static final String PICTURE5_BUTTON   = "image/button/chaise1Button.gif";
  private static final String PICTURE6_BUTTON   = "image/button/fauteuil2Button.gif";
  private static final String PICTURE7_BUTTON   = "image/button/fauteuil3Button.gif";
  private static final String PICTURE8_BUTTON   = "image/button/stereoButton.gif";
  private static final String PICTURE9_BUTTON   = "image/button/tv2Button.gif";
  private static final String PICTURE10_BUTTON  = "image/button/porteButton.gif";
  private static final String PICTURE11_BUTTON  = "image/button/fenetreButton.gif";
  private static final String PICTURE12_BUTTON  = "image/button/cadreButton.gif";
  private static final String PICTURE13_BUTTON  = "image/button/pianoButton.gif";
  private static final String PICTURE14_BUTTON  = "image/button/toiletteButton.gif";
  private static final String PICTURE15_BUTTON  = "image/button/evierButton.gif";

  private	JButton selectButton      = new JButton(para.getImageIcon(SELECT_BUTTON));
  private	JButton increaseButton    = new JButton(para.getImageIcon(INCREASE_BUTTON));
  private	JButton decreaseButton    = new JButton(para.getImageIcon(DECREASE_BUTTON));
  private	JButton picture1Button  	= new JButton(para.getImageIcon(PICTURE1_BUTTON));
  private	JButton picture2Button  	= new JButton(para.getImageIcon(PICTURE2_BUTTON));
  private	JButton picture3Button  	= new JButton(para.getImageIcon(PICTURE3_BUTTON));
  private	JButton picture4Button  	= new JButton(para.getImageIcon(PICTURE4_BUTTON));
  private	JButton picture5Button  	= new JButton(para.getImageIcon(PICTURE5_BUTTON));
  private	JButton picture6Button  	= new JButton(para.getImageIcon(PICTURE6_BUTTON));
  private	JButton picture7Button  	= new JButton(para.getImageIcon(PICTURE7_BUTTON));
  private	JButton picture8Button  	= new JButton(para.getImageIcon(PICTURE8_BUTTON));
  private	JButton picture9Button   	= new JButton(para.getImageIcon(PICTURE9_BUTTON));
  private	JButton picture10Button 	= new JButton(para.getImageIcon(PICTURE10_BUTTON));
  private	JButton picture11Button 	= new JButton(para.getImageIcon(PICTURE11_BUTTON));
  private	JButton picture12Button 	= new JButton(para.getImageIcon(PICTURE12_BUTTON));
  private	JButton picture13Button 	= new JButton(para.getImageIcon(PICTURE13_BUTTON));
  private	JButton picture14Button 	= new JButton(para.getImageIcon(PICTURE14_BUTTON));
  private	JButton picture15Button 	= new JButton(para.getImageIcon(PICTURE15_BUTTON));

  private int selectedButton = SELECT;

  public AppToolBar() {
  	super();

    this.setMargin(new Insets(5,0,5,19));

    selectButton.setActionCommand("Select");
    selectButton.setToolTipText(selectTip);
    selectButton.addActionListener(this);

    increaseButton.setActionCommand("Increase");
    increaseButton.setToolTipText(increaseTip);
    increaseButton.addActionListener(this);

    decreaseButton.setActionCommand("Decrease");
    decreaseButton.setToolTipText(decreaseTip);
    decreaseButton.addActionListener(this);

    picture1Button.setActionCommand("Picture1");
    picture1Button.setToolTipText(picture1Tip);
    picture1Button.addActionListener(this);

    picture2Button.setActionCommand("Picture2");
    picture2Button.setToolTipText(picture2Tip);
    picture2Button.addActionListener(this);

    picture3Button.setActionCommand("Picture3");
    picture3Button.setToolTipText(picture3Tip);
    picture3Button.addActionListener(this);

    picture4Button.setActionCommand("Picture4");
    picture4Button.setToolTipText(picture4Tip);
    picture4Button.addActionListener(this);

    picture5Button.setActionCommand("Picture5");
    picture5Button.setToolTipText(picture5Tip);
    picture5Button.addActionListener(this);

    picture6Button.setActionCommand("Picture6");
    picture6Button.setToolTipText(picture6Tip);
    picture6Button.addActionListener(this);

    picture7Button.setActionCommand("Picture7");
    picture7Button.setToolTipText(picture7Tip);
    picture7Button.addActionListener(this);

    picture8Button.setActionCommand("Picture8");
    picture8Button.setToolTipText(picture8Tip);
    picture8Button.addActionListener(this);

    picture9Button.setActionCommand("Picture9");
    picture9Button.setToolTipText(picture9Tip);
    picture9Button.addActionListener(this);

    picture10Button.setActionCommand("Picture10");
    picture10Button.setToolTipText(picture10Tip);
    picture10Button.addActionListener(this);

    picture11Button.setActionCommand("Picture11");
    picture11Button.setToolTipText(picture11Tip);
    picture11Button.addActionListener(this);

    picture12Button.setActionCommand("Picture12");
    picture12Button.setToolTipText(picture12Tip);
    picture12Button.addActionListener(this);

    picture13Button.setActionCommand("Picture13");
    picture13Button.setToolTipText(picture13Tip);
    picture13Button.addActionListener(this);

    picture14Button.setActionCommand("Picture14");
    picture14Button.setToolTipText(picture14Tip);
    picture14Button.addActionListener(this);

    picture15Button.setActionCommand("Picture15");
    picture15Button.setToolTipText(picture15Tip);
    picture15Button.addActionListener(this);

    this.setOrientation(VERTICAL);
    this.setFloatable(false);

    this.add(selectButton);
    this.add(increaseButton);
    this.add(decreaseButton);
    this.addSeparator();
    this.add(picture1Button);
    this.add(picture2Button);
    this.add(picture3Button);
    this.addSeparator();
    this.add(picture4Button);
    this.add(picture5Button);
    this.add(picture6Button);
    this.add(picture7Button);
    this.addSeparator();
    this.add(picture8Button);
    this.add(picture9Button);
    this.addSeparator();
    this.add(picture10Button);
    this.add(picture11Button);
    this.addSeparator();
    this.add(picture12Button);
    this.add(picture13Button);
    this.add(picture14Button);
    this.add(picture15Button);
  }

   public int getSelectedButton() {
    return selectedButton;
  }

  private void setSelectedButton(int aButton) {
    selectedButton = aButton;
  }

  private int getCommand(String aCommand) {
    int	action = -1;
    if     (aCommand.equals("Select"))     action = SELECT;
    else if(aCommand.equals("Increase"))   action = INCREASE;
    else if(aCommand.equals("Decrease"))   action = DECREASE;
    else if(aCommand.equals("Picture1"))   action = PICTURE1B;
    else if(aCommand.equals("Picture2"))   action = PICTURE2B;
    else if(aCommand.equals("Picture3"))   action = PICTURE3B;
    else if(aCommand.equals("Picture4"))   action = PICTURE4B;
    else if(aCommand.equals("Picture5"))   action = PICTURE5B;
    else if(aCommand.equals("Picture6"))   action = PICTURE6B;
    else if(aCommand.equals("Picture7"))   action = PICTURE7B;
    else if(aCommand.equals("Picture8"))   action = PICTURE8B;
    else if(aCommand.equals("Picture9"))   action = PICTURE9B;
    else if(aCommand.equals("Picture10"))  action = PICTURE10B;
    else if(aCommand.equals("Picture11"))  action = PICTURE11B;
    else if(aCommand.equals("Picture12"))  action = PICTURE12B;
    else if(aCommand.equals("Picture13"))  action = PICTURE13B;
    else if(aCommand.equals("Picture14"))  action = PICTURE14B;
    else if(aCommand.equals("Picture15"))  action = PICTURE15B;
    return action;
  }

  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    switch (this.getCommand(command)) {
      case SELECT:     this.setSelectedButton(SELECT);
                       break;
      case INCREASE:   this.setSelectedButton(INCREASE);
                       break;
      case DECREASE:   this.setSelectedButton(DECREASE);
                       break;
      case PICTURE1B:  this.setSelectedButton(PICTURE1B);
                       break;
      case PICTURE2B:  this.setSelectedButton(PICTURE2B);
                       break;
      case PICTURE3B:  this.setSelectedButton(PICTURE3B);
                       break;
      case PICTURE4B:  this.setSelectedButton(PICTURE4B);
                       break;
      case PICTURE5B:  this.setSelectedButton(PICTURE5B);
                       break;
      case PICTURE6B:  this.setSelectedButton(PICTURE6B);
                       break;
      case PICTURE7B:  this.setSelectedButton(PICTURE7B);
                       break;
      case PICTURE8B:  this.setSelectedButton(PICTURE8B);
                       break;
      case PICTURE9B:  this.setSelectedButton(PICTURE9B);
                       break;
      case PICTURE10B: this.setSelectedButton(PICTURE10B);
                       break;
      case PICTURE11B: this.setSelectedButton(PICTURE11B);
                       break;
      case PICTURE12B: this.setSelectedButton(PICTURE12B);
                       break;
      case PICTURE13B: this.setSelectedButton(PICTURE13B);
                       break;
      case PICTURE14B: this.setSelectedButton(PICTURE14B);
                       break;
      case PICTURE15B: this.setSelectedButton(PICTURE15B);
                       break;
    }
  }
}
